<?php
  include_once('./queries/utils.inc.php');

  function jobHistory_agg_query($groupFields,
                                $aggFuncs,
                                $statusFilters,
                                $interval_scalar,
				$interval_unit,
                                $connection) {

    $fldCount = 0;
    $sql = "SELECT ";
    foreach($groupFields as $group) {
      if ($fldCount>0) $sql = $sql . ", ";
      $sql = $sql . "h.{$group}";
      $fldCount++;
    }
    
    foreach($aggFuncs as $agg) {
      if($fldCount>0) $sql = $sql . ", ";
      $sql = $sql . $agg["func"];
      if ($agg["field"] == "*") {
	$sql = $sql . "(*)";
      } else {
	$sql = $sql . "(h." . $agg["field"] . ")";
      }
      $fldCount++;
    }

    $sql = $sql = $sql . " FROM Jobs_Horizontal_History h " .
                  "WHERE " . 
	            "h.owner = '{$_SESSION["loginUsername"]}' " .
	            "AND h.enteredcurrentstatus >= " .
                      " (current_timestamp - " . 
                         get_interval($interval_scalar, $interval_unit) . 
                      ") ";
    //echo $sql;
    //get the jobstatus filters here
    if (count($statusFilters) > 0) {
      $sql = $sql . "AND (";
      $curFilter = 0;
      foreach($statusFilters as $status) {
        if ($curFilter > 0) $sql = $sql . " OR ";
        if ($status == "waiting") {
          $sql = $sql . "(h.jobstatus IS NULL OR h.jobstatus=0 OR h.jobstatus=1)";
        } elseif ($status == "held") {
          $sql = $sql . "(h.jobstatus=5)";
        } elseif ($status == "running") {
          $sql = $sql . "(h.jobstatus=2)";
        } elseif ($status == "completed") {
          $sql = $sql . "(h.jobstatus=4)";
        } elseif ($status == "removed") {
          $sql = $sql . "(h.jobstatus=3)";
        }
      }
      $sql = $sql . ") ";
    }

    //now the group by stuff
    if (count($groupFields)>0) {
      $sql = $sql . " GROUP BY ";
      $fldCount = 0;
      foreach($groupFields as $group) {
        if ($fldCount>0) $sql = $sql . ", ";
        $sql = $sql . "h.{$group}";
        $fldCount++;
      }
    }
    //echo $sql;
    $result = get_recordset($connection, $sql);
    //echo "About to exit jobHistory_agg_query...";
    return $result;
  }


  function count_user_job_history_by_status($connection, $statusFilters, 
					    $interval_scalar, $interval_unit) {
    $groupBy = array();
    $aggs = array();
    $aggs[0] = array();
    $aggs[0]["func"] = "count";
    $aggs[0]["field"] = "*";

    if ($interval_scalar == "none") {
	$interval_scalar = "1000";
	$interval_unit = "year";
    }

    return get_scalar(jobHistory_agg_query($groupBy, $aggs, $statusFilters, $interval_scalar, $interval_unit, $connection));
  }

  function jobHistoryList($connection, $index, $params, $statusFilters, $interval_scalar, $interval_unit, $owner, $pn) {
    $effOwner = $owner;
    if ($effOwner == "<b>Total</b>") unset($owner);

    $date = TS_FORMAT;

    $sql = "SELECT h.scheddname, h.cluster_id, h.proc_id, " .
           "to_char(h.qdate, '{$date}'), h.exitcode, " .
           "h.jobstatus, h.remotewallclocktime, " .
           "to_char(h.completiondate, '{$date}') " .
           "FROM Jobs_Horizontal_History h " .
      	   "WHERE ";
           if ($_SESSION["administrator"] === true) {
             if (isset($owner)) $sql = $sql . "h.owner = '{$owner}' AND ";
           } else {
             //not an admin, so force job history privacy
             $sql = $sql . "h.owner = '{$_SESSION["loginUsername"]}' AND ";
           }
	     $sql = $sql . "h.enteredcurrentstatus >= " .
               " (current_timestamp - " .
                 get_interval($interval_scalar, $interval_unit) .
               ") ";

    if(isset($params)) {
      foreach($params as $field => $value) {
        $sql = $sql . "AND {$field}='{$value}' ";
      }
    }

    //get the jobstatus filters here
    if (count($statusFilters) > 0) {
      $sql = $sql . "AND (";
      $curFilter = 0;
      foreach($statusFilters as $status) {
        if ($curFilter > 0) $sql = $sql . " OR ";
        if ($status == "waiting") {
          $sql = $sql . "(h.jobstatus IS NULL OR h.jobstatus=0 OR h.jobstatus=1)";
        } elseif ($status == "held") {
          $sql = $sql . "(h.jobstatus=5)";
        } elseif ($status == "running") {
          $sql = $sql . "(h.jobstatus=2)";
        } elseif ($status == "completed") {
          $sql = $sql . "(h.jobstatus=4)";
        } elseif ($status == "removed") {
          $sql = $sql . "(h.jobstatus=3)";
        }
      }
      $sql = $sql . ") ";
    }

    $rcount = get_recordcount($connection, $sql);

    $sql = $sql . "ORDER BY h.enteredcurrentstatus desc, h.scheddname, h.cluster_id, h.proc_id ";
    $sql = do_pagination_rewriting($pn, $rcount, $sql); 

    //echo $sql;
    unset($_SESSION["{$index}"]);
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["params"] = $params;
    $_SESSION["{$index}"]["status"] = $statusFilters;
    $_SESSION["{$index}"]["interval_scalar"] = $interval_scalar;
    $_SESSION["{$index}"]["interval_unit"] = $interval_unit;
    $_SESSION["{$index}"]["owner"] = $effOwner;

    $_SESSION["{$index}"]["title"]="Paramaterized job history list.";        
    $_SESSION["{$index}"]["message"] = "Paramaterized job history list.";
    
    $fields = array();
    $fields[0] = "scheddname";
    $fields[1] = "cid";
    $fields[2] = "pid";
    $fields[3] = "qdate";
    $fields[4] = "exitcode";
    $fields[5] = "jobstatus";
    $fields[6] = "remotewallclocktime";
    $fields[7] = "completiondate";

    $rs = new recordset($rcount, $fields, get_recordset($connection, $sql));
    return $rs;
  }

  function single_proc_short_history_query($connection, $index, $schedd, $cid, $pid) {
    $date = TS_FORMAT;
    $sql = "SELECT h.scheddname, h.cluster_id, h.proc_id, " .
           "to_char(h.qdate, '{$date}'), " .
           "h.exitcode, h.jobstatus, h.remotewallclocktime, " .
           "to_char(h.completiondate, '{$date}') " .
           "FROM jobs_horizontal_history h " .
           "WHERE h.scheddname='{$schedd}' " .
           "AND h.cluster_id='{$cid}' " .
           "AND h.proc_id='{$pid}' ";
           if (!($_SESSION["administrator"] === true)) {
	      $sql = $sql . "AND h.owner = '{$_SESSION["loginUsername"]}' ";
           }
           //$sql = $sql . ";";
    //echo $sql;
    unset($_SESSION["{$index}"]);
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about job {$schedd}.{$cid}.{$pid}";
    $_SESSION["{$index}"]["message"]="Historical information about job {$schedd}.{$cid}.{$pid}";

    $fields=array();
    $fields[0]="scheddname";
    $fields[1]="cid";
    $fields[2]="pid";
    $fields[3]="qdate";
    $fields[4]="exitcode";
    $fields[5]="jobstatus";
    $fields[6]="remotewallclocktime";
    $fields[7]="completiondate";

    $rs = new recordset(1, $fields, get_recordset($connection, $sql));
    return $rs;
  }
 
  function single_proc_horizontal_history_query($connection, $index, 
           $schedd, $cid, $pid) {
    $date = TS_FORMAT;
    $sql = "SELECT scheddname, scheddbirthdate, cluster_id, proc_id, " .
           "to_char(qdate, '{$date}'), owner, globaljobid, numckpts, " .
           "numrestarts, numsystemholds, condorversion, condorplatform, " .
           "rootdir, iwd, jobuniverse, cmd, minhosts, maxhosts, jobprio, " .
           "negotiation_user_name, env, userlog, coresize, killsig, " .
           "stdin, transferin, stdout, transferout, stderr, transfererr, " .
           "shouldtransferfiles, transferfiles, executablesize, diskusage, " .
           "filesystemdomain, args, to_char(lastmatchtime, '{$date}'), " .
           "numjobmatches, to_char(jobstartdate, '{$date}'), " .
           "to_char(jobcurrentstartdate, '{$date}'), jobruncount, " .
           "filereadcount, filereadbytes, filewritecount, filewritebytes, " .
           "fileseekcount, totalsuspensions, imagesize, exitstatus, " .
           "localusercpu, localsyscpu, remoteusercpu, remotesyscpu, " .
           "bytessent, bytesrecvd, rscbytessent, rscbytesrecvd, exitcode, " .
           "jobstatus, to_char(enteredcurrentstatus, '{$date}'), " .
           "remotewallclocktime, lastremotehost, " .
           "to_char(completiondate, '{$date}'), enteredhistorytable " .
           "FROM Jobs_Horizontal_History h " .
           "WHERE h.scheddname='{$schedd}' " .
           "AND h.cluster_id='{$cid}' " .
           "AND h.proc_id='{$pid}' ";
           if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND h.owner = '{$_SESSION["loginUsername"]}' ";
           }
           //$sql = $sql . ";";
    //echo $sql;
    
    unset($_SESSION["{$index}"]);
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Latest information about job {$schedd}.{$cid}.{$pid}";
    $_SESSION["{$index}"]["message"]="Latest information about job {$schedd}.{$cid}.{$pid}";

    $fields=array();
    $fields[0]="scheddname";
    $fields[1]="scheddbirthdate";
    $fields[2]="cid";
    $fields[3]="pid";
    $fields[4]="qdate";
    $fields[5]="owner";
    $fields[6]="globaljobid";
    $fields[7]="numckpts";
    $fields[8]="numrestarts";
    $fields[9]="numsystemholds";
    $fields[10]="condorversion";
    $fields[11]="condorplatform";
    $fields[12]="rootdir";
    $fields[13]="iwd";
    $fields[14]="jobuniverse";
    $fields[15]="cmd";
    $fields[16]="minhosts";
    $fields[17]="maxhosts";
    $fields[18]="jobprio";
    $fields[19]="negotiation_user_name";
    $fields[20]="env";
    $fields[21]="userlog";
    $fields[22]="coresize";
    $fields[23]="killsig";
    $fields[24]="stdin";
    $fields[25]="transferin";
    $fields[26]="stdout";
    $fields[27]="transferout";
    $fields[28]="stderr";
    $fields[29]="transfererr";
    $fields[30]="shouldtransferfiles";
    $fields[31]="transferfiles";
    $fields[32]="executablesize";
    $fields[33]="diskusage";
    $fields[34]="filesystemdomain";
    $fields[35]="args";
    $fields[36]="lastmatchtime";
    $fields[37]="numjobmatches";
    $fields[38]="jobstartdate";
    $fields[39]="jobcurrentstartdate";
    $fields[40]="jobruncount";
    $fields[41]="filereadcount";
    $fields[42]="filereadbytes";
    $fields[43]="filewritecount";
    $fields[44]="filewritebytes";
    $fields[45]="fileseekcount";
    $fields[46]="totalsuspensions";
    $fields[47]="imagesize";
    $fields[48]="exitstatus";
    $fields[49]="localusercpu";
    $fields[50]="localsyscpu";
    $fields[51]="remoteusercpu";
    $fields[52]="remotesyscpu";
    $fields[53]="bytessent";
    $fields[54]="bytesrecvd";
    $fields[55]="rscbytessent";
    $fields[56]="rscbytesrecvd";
    $fields[57]="exitcode";
    $fields[58]="jobstatus";
    $fields[59]="enteredcurrentstatus";
    $fields[60]="remotewallclocktime";
    $fields[61]="lastremotehost";
    $fields[62]="completiondate";
    $fields[63]="enteredhistorytable";

    $rs = new recordset(1, $fields, get_recordset($connection, $sql));
    return $rs;
  }

  function single_proc_vertical_history_query($connection, $index, $schedd, $cid, $pid) {
    
    $sql = "SELECT hv.attr, hv.val " .
           "FROM Jobs_Vertical_History hv, Jobs_Horizontal_History hh " . 
           "WHERE hv.scheddname='{$schedd}' " .
              "AND hv.cluster_id='{$cid}' ". 
              "AND hv.proc_id='{$pid}' " .
              "AND hv.scheddname=hh.scheddname " .
              "AND hv.cluster_id=hh.cluster_id " .
              "AND hv.proc_id=hh.proc_id ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }

			  $rcount = get_recordcount($connection, $sql);
			  //$sql = $sql . ";";

    //echo $sql;
    
    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about job {$schedd}.{$cid}.{$pid}.";

    $fields=array();
    $fields[0]="Attribute";
    $fields[1]="Value";

    $rs = new recordset($rcount, $fields, get_recordset($connection, $sql));
    return $rs;
  }

  function single_proc_runs_history_query($connection, $index, $schedd, $cid, $pid) {

    $date = TS_FORMAT;

    $sql = "SELECT r.run_id, r.machine_id, r.spid," .
           "to_char(r.startts, '{$date}'), to_char(r.endts, '{$date}'), " .
           "r.endtype, r.endmessage " .
           "FROM runs r, Jobs_Horizontal_History hh " . 
           "WHERE hh.scheddname='{$schedd}' " .
              "AND hh.cluster_id='{$cid}' ". 
              "AND hh.proc_id='{$pid}' " .
              "AND r.scheddname=hh.scheddname " .
              "AND r.cluster_id=hh.cluster_id " .
              "AND r.proc_id=hh.proc_id ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }
			  $rcount = get_recordcount($connection, $sql);
           $sql = $sql . "ORDER BY r.endts desc";

    //echo $sql;

    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about runs for job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about runs for job {$schedd}.{$cid}.{$pid}.";

    $_SESSION["{$index}"]["recSet"] = get_recordset($connection, $sql);
    $_SESSION["{$index}"]["time"] = date("r", time());

    $fields=array();
    $fields[0]="run_id";
    $fields[1]="machine_id";
    $fields[2]="spid";
    $fields[3]="startts";
    $fields[4]="endts";
    $fields[5]="endtype";
    $fields[6]="endmessage";

    $rs = new recordset($rcount, $fields, get_recordset($connection, $sql));
    return $rs;
  }

  // events related 
  function single_proc_events_history_query($connection, $index, $schedd, $cid, $pid) {
    
    $date = TS_FORMAT;
    $sql = "SELECT e.eventtype, to_char(e.eventtime, '{$date}'), " .
           "e.description " .
           "FROM events e, Jobs_Horizontal_History hh " . 
           "WHERE hh.scheddname='{$schedd}' " .
              "AND hh.cluster_id='{$cid}' ". 
              "AND hh.proc_id='{$pid}' " .
              "AND e.scheddname=hh.scheddname " .
              "AND e.cluster_id=hh.cluster_id " .
              "AND e.proc_id=hh.proc_id ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }
			  $rcount = get_recordcount($connection, $sql);
           $sql = $sql . "ORDER BY e.eventtime desc ";

    //echo $sql;

    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about events for job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about events for job {$schedd}.{$cid}.{$pid}.";

    $_SESSION["{$index}"]["recSet"] = get_recordset($connection, $sql);
    $_SESSION["{$index}"]["time"] = date("r", time());

    $fields=array();
    $fields[0]="eventtype";
    $fields[1]="eventtime";
    $fields[2]="description";

    $rs = new recordset($rcount, $fields, get_recordset($connection, $sql));
    return $rs;
  }

  function single_proc_matches_history_query($connection, $index, 
        $schedd, $cid, $pid) {
    
    $date = TS_FORMAT;
    $sql = "SELECT to_char(m.match_time, '{$date}') AS match_time, " .
           "m.username, m.startdname, m.remote_user, m.remote_priority " .
           "FROM matches m, history_horizontal hh " . 
           "WHERE m.scheddname='{$schedd}' " .
              "AND m.proc='{$cid}' ". 
              "AND (m.proc='{$pid}' or m.proc=0)" .
              "AND m.scheddname=hh.scheddname " .
              "AND m.cluster_id=hh.cluster_id " .
              "AND m.proc=hh.proc ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }
           $sql = $sql . "ORDER BY match_time desc";

    //echo $sql;
    $result=get_recordset($connection, $sql);
    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about matches for job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about matches for job {$schedd}.{$cid}.{$pid}.";

    $_SESSION["{$index}"]["recSet"] = get_recordset($connection, $sql);
    $_SESSION["{$index}"]["time"] = date("r", time());

    $_SESSION["{$index}"]["fields"]=array();
    $_SESSION["{$index}"]["fields"][0]="match_time";
    $_SESSION["{$index}"]["fields"][1]="username";
//    $_SESSION["{$index}"]["fields"][2]="scheddname";
//    $_SESSION["{$index}"]["fields"][3]="cluster";
//    $_SESSION["{$index}"]["fields"][4]="proc";
//    $_SESSION["{$index}"]["fields"][5]="globaljobid";
    $_SESSION["{$index}"]["fields"][2]="startdname";
    $_SESSION["{$index}"]["fields"][3]="remote_user";
    $_SESSION["{$index}"]["fields"][4]="remote_priority";

  }

  function single_proc_rejects_history_query($connection, $index, $schedd, $cid, $pid) {
    
    $date = TS_FORMAT;
    $sql = "SELECT to_char(r.reject_time, '{$date}') as reject_time, " .
           "r.username, r.startdname, r.diagnosis " . 
           "FROM rejects r, jobs_horizontal_history hh " . 
           "WHERE hh.scheddname='{$schedd}' " .
              "AND hh.cluster_id='{$cid}' ". 
              "AND hh.proc_id='{$pid}' " .
              "AND r.scheddname=hh.scheddname " .
              "AND r.cluster_id=hh.cluster_id " .
              "AND r.proc_id=hh.proc_id ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }
           $sql = $sql . "ORDER BY reject_time desc";

    //echo $sql;
    /*
    $result=get_recordset($connection, $sql);
    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about rejects for job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about rejects for job {$schedd}.{$cid}.{$pid}.";

    $_SESSION["{$index}"]["recSet"] = get_recordset($connection, $sql);
    $_SESSION["{$index}"]["time"] = date("r", time());

    $_SESSION["{$index}"]["fields"]=array();
    $_SESSION["{$index}"]["fields"][0]="reject_time";
    $_SESSION["{$index}"]["fields"][1]="username";
//    $_SESSION["{$index}"]["fields"][2]="scheddname";
//    $_SESSION["{$index}"]["fields"][3]="cluster";
//    $_SESSION["{$index}"]["fields"][4]="proc";
//    $_SESSION["{$index}"]["fields"][5]="globaljobid";
    $_SESSION["{$index}"]["fields"][2]="startdname";
    $_SESSION["{$index}"]["fields"][3]="diagnosis";
*/
  }

  
  function single_proc_matches_history_summary($connection, $index, $schedd, $cid, $pid) {
    
    $date = TS_FORMAT;
    $sql = "SELECT to_char(m.match_time, '{$date}') AS match_time, " .
           "m.scheddname, m.cluster_id, m.proc, m.startdname " . 
           "FROM matches m, jobs_horizontal_history hh " . 
           "WHERE m.scheddname='{$schedd}' " .
              "AND m.cluster_id='{$cid}' ". 
              //"AND (m.proc_id='{$pid}' or m.proc_id=0)" .
              "AND m.scheddname=hh.scheddname " .
              "AND m.cluster_id=hh.cluster_id " .
              "AND m.proc_id=hh.proc_id ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }
           //"GROUP BY match_time, m.scheddname, m.cluster_id, m.proc_id " .
           $sql = $sql . "ORDER BY match_time desc, m.scheddname, m.cluster_id, m.proc_id desc ";

    //echo $sql;
    $result=get_recordset($connection, $sql);
    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about matches for job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about matches for job {$schedd}.{$cid}.{$pid}.";

    $_SESSION["{$index}"]["recSet"] = get_recordset($connection, $sql);
    $_SESSION["{$index}"]["time"] = date("r", time());

    $_SESSION["{$index}"]["fields"]=array();
    $_SESSION["{$index}"]["fields"][0]="match_time";
    $_SESSION["{$index}"]["fields"][1]="scheddname";
    $_SESSION["{$index}"]["fields"][2]="cluster";
    $_SESSION["{$index}"]["fields"][3]="proc";
    $_SESSION["{$index}"]["fields"][4]="startdname";

  }

  function single_proc_rejects_history_summary($connection, $index, $schedd, $cid, $pid) {
    
    $date = TS_FORMAT;
    $sql = "SELECT to_char(r.reject_time, '{$date}') AS reject_time, " .
           "r.scheddname, r.cluster_id, r.proc_id, r.diagnosis, count(*) " . 
           "FROM rejects r, history_horizontal hh " . 
           "WHERE hh.scheddname='{$schedd}' " .
              "AND hh.cluster_id='{$cid}' ". 
              "AND hh.proc_id='{$pid}' " .
              "AND r.scheddname=hh.scheddname " .
              "AND r.cluster_id=hh.cluster_id " .
              "AND r.proc_id=hh.proc_id ";
              if (!($_SESSION["administrator"] === true)) {
	        $sql = $sql . "AND hh.owner = '{$_SESSION["loginUsername"]}' ";
              }
			  $sql = $sql . "GROUP BY reject_time, r.scheddname, r.cluster_id, r.proc_id, r.diagnosis ";
			  $rcount = get_recordcount($connection, $sql);
			  $sql = $sql . 
				  "ORDER BY r.scheddname, r.cluster_id, r.proc_id, reject_time desc";

    //echo $sql;
    /*
    $result=get_recordset($connection, $sql);
    unset($_SESSION["{$index}"]);    
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"]="Historical information about rejects for job {$schedd}.{$cid}.{$pid}.";
    $_SESSION["{$index}"]["message"]="Historical information about rejects for job {$schedd}.{$cid}.{$pid}.";

    $_SESSION["{$index}"]["recSet"] = get_recordset($connection, $sql);
    $_SESSION["{$index}"]["time"] = date("r", time());

    $_SESSION["{$index}"]["fields"]=array();
    $_SESSION["{$index}"]["fields"][0]="reject_time";
    $_SESSION["{$index}"]["fields"][1]="scheddname";
    $_SESSION["{$index}"]["fields"][2]="cluster";
    $_SESSION["{$index}"]["fields"][3]="proc";
    $_SESSION["{$index}"]["fields"][4]="diagnosis";
    $_SESSION["{$index}"]["fields"][5]="reject_count";
*/
  }
?>
